<template>
	<view>		
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="content">我发布的任务</block>
		</cu-custom>
		<!-- 加载动画 -->
		<view v-if="pageLoad" class="text-gray padding justify-center flex align-center">
			<u-loading mode="circle" color="#2979ff" size="40"></u-loading>
			<view class="margin-left-sm">加载中...</view>
		</view>
		<view v-if="!pageLoad">
			<view class="text-gray padding justify-center flex" v-if="Object.keys(list).length === 0" ><text>暂无数据</text></view>			
			<view class="cu-card case isCard">
				<view class="cu-item shadow" v-for="(item,index) in list" :key="index">
					<view class="image">
						<view class="cu-bar bg-shadeBottom"> <text class="text-cut">{{item.title}}</text></view>
					</view>
					<view class="text-content padding-sm text-cut" style="width:100%;">
						{{item.time}}    {{item.address}}    {{item.price}}
					</view>
					<view class="content flex-sub">				
						<view class="text-gray flex justify-around padding-bottom">
							<view @click="goEdit(item._id)" class="text-blue"><text class="cuIcon-edit"></text> 编辑</view>
							<view @click="goDetail(item._id)" class="text-green"><text class="cuIcon-attention"></text> 查看</view>
							<view @click="del(item._id)" class="text-red"><text class="cuIcon-delete"></text>删除</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				isFirst:true,
				pageLoad: true,
				userid:this.$store.getters.userInfo._id
			}
		},
		onLoad:function(){
			this.getMyPublish()
		},
		onPullDownRefresh:function(){			 
			this.getMyPublish()
		}, 
		methods: {
			goDetail:function(id){
				uni.navigateTo({
					url:"/pages/user/mypublish/detail?id="+id
				})
			},
			goEdit:function(id){
				uni.navigateTo({
					url:"/pages/user/mypublish/edit?id="+id
				})
			},
			del:function(id){
				var that=this
				uni.showModal({
					title:"删除提示",
					content:"删除后不可恢复",
					success:function(res){
						if(res.confirm){
							uniCloud.callFunction({
								name:"task",
								data:{
									cloudAction:"delete",
									params:{
										id:id,
									}
								}
							}).then((res)=>{
								for(var i in that.list){
									if(that.list[i]._id==id){
										that.list.splice(i,1)									 
									}
								}
							})
						}
					}
				})
				
			},
			//获取我发布的文章
			getMyPublish(){
				uniCloud.callFunction({
					name: "getMyPublish",
					data: {
							userid:this.userid,
					}
				}).then((res) => {
					console.log(res);
					this.list=res.result.data;
					this.pageLoad = false
					}
				)
			}
		}
	}
</script>

<style lang="scss" scoped>
	
</style>
